// pages/wenjian/wenjian.js

import footer from '../../template/footer.js'
import {
  ajax,
  src,
  util
} from "../../utils/util.js";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showsantc:false,
    showdeltc:false,
    showupnametc:false,
    shownewwjtc:false,
    showsxtc:false,
    showjiahaotc:false,

    showyulantc:false,
    showjindutc:false,

    showpldeltc:false,
    shownotyulantc:false,

    per:0,
    count: 0, //计数器，初始值为0
    maxCount: 50, // 绘制一个圆环所需的步骤 
  
    countTimer: null,//定时器，初始值为null

    circle1:'',
    txt:0,

    // userId:2,

    nowwjjdata:'',

    headImg:[],

    newFolderName:"",


    wenlist:"",
    tulist:'',

    //显示所欲box
    tushowallbox:false,
    wenshowallbox:false,

    //全选全局字段
    tuselectall:false,
    wenselectall: false,


    // 筛选
    tutime:0,
    tupaixu:0,

    wentime: 0,
    wenpaixu: 0,

    //当前目录
    thismuluid:0,

    //当前操作块
    currentcaozuo:'',
    // 当前操作块,
    currentcaozuoindex:'',


    jindulist:[],

    yixuan:0,
    currentuuid:"",
    isAudit:false,



    idlist:""
  },

  tologin:function(){
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  
  computeryixuan:function(){

    var yixuan=0
    if(this.data.tushowallbox==true){
      this.data.tulist.forEach((value,index)=>{
        if (value.checked==true){
          yixuan++
        }
      })
    }
    if (this.data.wenshowallbox == true) {
      this.data.wenlist.forEach((value, index) => {
        if (value.checked == true) {
          yixuan++
        }
      })
    }

    console.log(yixuan)
    this.setData({
      yixuan:yixuan
    })
  },

  delnamezhi() {
    console.log('1111')
    this.setData({
      newFolderName: ''
    })
  },

  showtuallbox:function(){
    this.setData({
      tushowallbox:false,
      wenshowallbox:false,
    })

    if(this.data.tulist.length<=5){
      this.setData({
        tushowallbox: !this.data.tushowallbox
      })
    }else{
      this.totupage()
    }
   
  },
 
  showwenallbox: function () {
    this.setData({
      tushowallbox: false,
      wenshowallbox: false,
    })
    this.setData({
      wenshowallbox: !this.data.wenshowallbox
    })
  },

  quxiaoquanxuan:function(){
    this.setData({
      tushowallbox: false,
      wenshowallbox: false,
    })
  },

  toyiji:function(e){
    
    var index=e.currentTarget.dataset.index
    console.log(index)
    footer.toyiji(index)
  },
  // 跳转搜索页面
  tosearch: function () {
    wx.navigateTo({
      url: '/pages/search/search?thismuluid=' + 0,
    })
  },

  totupage:function(){
    wx.navigateTo({
      url: '/pages/tupage/tupage?thismuluid=' + this.data.thismuluid,     
    })
  },

  sleep(delay) {
    var start = (new Date()).getTime();
    while ((new Date()).getTime() - start < delay) {
      continue;
    }
  },


  per1(){
    var that=this
   

    that.data.countTimer=setInterval(function(){
      var perr = that.data.per
      that.setData({
        per:perr+2,
        
      })
      that.circle1.drawCircle('circle_draw1', 78, 7, that.data.per/100);  
      that.setData({
        txt: that.data.per/2,
      })
      if (that.data.per==200){
        clearInterval(that.data.countTimer)
      }
    },50)
  },
  

  selectitem:function(e){
    var index = e.currentTarget.dataset.index
    var str = 'tulist[' + index +'].checked'
    // console.log(index)
    // console.log(this.data.tulist[index].checked)
    this.setData({
      [str]: !this.data.tulist[index].checked
    })

    this.computeryixuan()
  },
  selectitem1: function (e) {
    var index = e.currentTarget.dataset.index
    var str = 'wenlist[' + index + '].checked'
    // console.log(index)
    // console.log(this.data.wenlist[index].checked)
    this.setData({
      [str]: !this.data.wenlist[index].checked
    })
    this.computeryixuan()
  },

  selectall:function(){
    var that=this
    if (that.data.tushowallbox==true){
      that.setData({
        tuselectall: !that.data.tuselectall
      })

      that.data.tulist.forEach((value,index)=>{
        that.setData({
          ['tulist[' + index + '].checked']: that.data.tuselectall
        })
      })
    }
    if (that.data.wenshowallbox == true) {
      that.setData({
        wenselectall: !that.data.wenselectall
      })
      that.data.wenlist.forEach((value, index) => {
        that.setData({
          ['wenlist[' + index + '].checked']: that.data.wenselectall
        })
      })
    }

    // console.log(1111111)
    this.computeryixuan()
  },


  // bindtouchstart：触屏开始时间
  // bindtouchend ：触屏结束时间
  // bindlongtap：绑定长按事件
  // catchtap：单击事件
  mytouchstart: function (e) { //记录触屏开始时间
    this.setData({ start: e.timeStamp })
  },
  mytouchend: function (e) { //记录触屏结束时间
    this.setData({ end: e.timeStamp })
  },
  deleteitem: function (e) { //长按事件内容
    console.log('长按事件内容')
    if(this.data.tushowallbox==true||this.data.wenshowallbox==true){
      return
    }

    this.tc('', 1)
    var index = e.currentTarget.dataset.index

    var style = 'tu'
    this.setData({
      currentcaozuoindex: index,
      currentcaozuo: style
    })
   
  },
  onLinkDatail: function (e) { //单击事件内容
    if (this.data.end - this.data.start < 350) {
      console.log('单击事件内容')

      if (this.data.tushowallbox == true || this.data.wenshowallbox == true) {
        return
      }
      console.log(e)
      var current = e.currentTarget.dataset.src;
      var index = e.currentTarget.dataset.index;
      var imglist = []
      this.data.tulist.forEach((value, index) => {
        imglist.push(value.previewUrl)
      })
      console.log(current)

      var newlist=[]

      for (var i = index; i < imglist.length;i++){
        newlist.push(imglist[i])
      }

      for (var i = 0; i < index; i++) {
        newlist.push(imglist[i])
      }


      wx.previewImage({
        current: current, // 当前显示图片的http链接
        urls: newlist // 需要预览的图片http链接列表
      })
    }
  },


  

  // 批量
  pl_fx: function () {
    var that = this

    var idlist = []
    if (that.data.tushowallbox == true) {
      that.data.tulist.forEach((value, index) => {
        if (value.checked == true) {
          idlist.push(value.id)
        }
      })
    }
    if (that.data.wenshowallbox == true) {
      that.data.wenlist.forEach((value, index) => {
        if (value.checked == true) {
          idlist.push(value.id)
        }
      })
    }
    if (idlist.length==0){
      wx.showToast({
        title: '请选择文件',
        icon: 'none',
        duration: 2000
      })
      return
    }

    wx.navigateTo({
      url: '/pages/fenxiang/fenxiang?idlist=' + idlist,
    })
  },
  pl_sc:function(){
    var that = this
    var idlist=[]
    if (that.data.tushowallbox == true) {
      that.data.tulist.forEach((value, index) => {
        if(value.checked==true){
          idlist.push(value.id)
        }
      })
    }
    if (that.data.wenshowallbox == true) {
      that.data.wenlist.forEach((value, index) => {
        if (value.checked == true) {
          idlist.push(value.id)
        }
      })
    }

    if (idlist.length == 0) {
      wx.showToast({
        title: '请选择文件',
        icon: 'none',
        duration: 2000
      })
      return
    }

    that.setData({
      tushowallbox: false,
      wenshowallbox:false,
      idlist:idlist,
      showpldeltc:true,
    })
  
  },

  pl_scfun: function (){
    // /applet/appletDelete
    var that = this
    ajax('/applet/appletDelete', {
      data: {
        id: that.data.idlist
      },
      header: {
        "Accept": "application/json" // 默认值
      },
      method: "post",
    }, res => {
      console.log(res.data.list)
      if (res.msg == "SUCCESS") {
        wx.showToast({
          title: '删除成功',
          icon: 'success',
          duration: 2000
        })
        that.setData({
          idlist:[]
        })

        that.plscquxiao()

        that.gettulist(that.data.thismuluid, that.data.tutime, that.data.tupaixu)
        that.getwenlist(that.data.thismuluid, that.data.wentime, that.data.wenpaixu)

        // if (that.data.tushowallbox == true) {
        //   that.showtuallbox()
          

        // }
        // if (that.data.wenshowallbox == true) {
        //   that.showwenallbox()
          
        // }
      }
    })
  },


  showshaixuanbox:function(e){
    var style = e.currentTarget.dataset.index
     

    if (this.data.tushowallbox == true || this.data.wenshowallbox==true){
      return
    }

    if (style == '1') {

      if (this.data.tulist.length > 5) {
        this.totupage()
        return
      }

      this.setData({
        currentcaozuo: 'tu'
      })
    }
    if (style == '2') {
      this.setData({
        currentcaozuo: 'wen'
      })
    }

    
    this.tc('',5)
    
  },

  selectpaixu: function (e) {
    var index = e.currentTarget.dataset.index

    if (this.data.currentcaozuo=='tu'){
      this.setData({
        tupaixu: Number(index)
      })
    }
    if (this.data.currentcaozuo == 'wen') {
      this.setData({
        wenpaixu: Number(index)
      })
    }
  },

  selecttime: function (e) {
    console.log(e)
    var index = e.currentTarget.dataset.index

    if (this.data.currentcaozuo == 'tu') {
      this.setData({
        tutime: Number(index)
      })
    }
    if (this.data.currentcaozuo == 'wen') {
      this.setData({
        wentime: Number(index)
      })
    }
  },


  cx_getlist:function(){
    this.tc('',5)
    if (this.data.currentcaozuo == 'tu') {
      this.gettulist( this.data.thismuluid, this.data.tutime, this.data.tupaixu)
    }
    if (this.data.currentcaozuo == 'wen') {
      this.getwenlist( this.data.thismuluid, this.data.wentime, this.data.wenpaixu)
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */



  onLoad: function (options) {
   

    // this.drew()
    // userId, parentId, timeSlot, orderType
   
  },

  // 获取图片
  gettulist: function( parentId, timeSlot, orderType) {
    ajax('/applet/viewPicture', {
      data: {
        // 为必填 
        // userId: userId,
        // 为必填 如果是根目录请传0
        parentId: parentId,
        // 选填 0 全部，1 今天，2 近三天，3 近7天， 4近30天 
        timeSlot: timeSlot,
        // 筛选类型 ，筛选时（ 0 最近查看，1 最近上传）展示时（2 最近 3，常用） 
        orderType: orderType,
        page:1 ,
        size:100
    },
      header: {
        "Accept": "application/json" // 默认值
    },
      method: "post",
    }, res => {
      res.data.list.forEach((valve, index) => {
        valve.checked = false

        if (valve.fileType == 0) {

          valve.fileFormat = valve.fileName
          valve.firstname = valve.fileName
        } else {

          let fileName = valve.fileName.lastIndexOf(".");//取到文件名开始到最后一个点的长度
          let fileNameLength = valve.fileName.length;//取到文件名长度
          let fileFormat = valve.fileName.substring(fileName + 1, fileNameLength);//截
          let firstname = valve.fileName.substring(0, fileName);//截
          valve.fileFormat = fileFormat
          valve.firstname = firstname
        }
      })
      console.log(res.data.list)

      this.setData({
        tulist: res.data.list
      })
      
    })
  },

  // 获取文件
  getwenlist: function ( parentId, timeSlot, orderType) {
    ajax('/applet/viewFile', {
      data: {
        
        // 为必填 如果是根目录请传0
        parentId: parentId,
        // 选填 0 全部，1 今天，2 近三天，3 近7天， 4近30天 
        timeSlot: timeSlot,
        // 筛选类型 ，筛选时（ 0 最近查看，1 最近上传）展示时（2 最近 3，常用） 
        orderType: orderType,
        page: 1,
        size: 100
      },
      header: {
        "Accept": "application/json" // 默认值
      },
      method: "post",
    }, res => {
      if (res.msg == "SUCCESS") {
        res.data.list.forEach((valve, index) => {
          valve.checked = false

          // valve.tempFilePath = ''

          if (valve.fileType == 0) {

            valve.fileFormat = valve.fileName
            valve.firstname = valve.fileName
          } else {

            let fileName = valve.fileName.lastIndexOf(".");//取到文件名开始到最后一个点的长度
            let fileNameLength = valve.fileName.length;//取到文件名长度
            let fileFormat = valve.fileName.substring(fileName + 1, fileNameLength);//截
            let firstname = valve.fileName.substring(0, fileName);//截
            valve.fileFormat = fileFormat
            valve.firstname = firstname
          }
        })
        console.log(res.data.list)

        this.setData({
          wenlist: res.data.list
        })
      }else{
        wx.showToast({
          title: res.msg,
          icon: 'none',
          duration: 2000
        })
      }
    })
  },

  // 新建文件夹
  createFolder: function ( parentId, fileName) {

    if (fileName == '') {
      wx.showToast({
        title: '文件夹名称不能为空',
        icon: 'none',
        duration: 2000
      })
      return
    }

    ajax('/applet/appletCreateFolder', {
      data: {
        // 为必填  userId: userId,
        // 为必填 如果是根目录请传0
        parentId: parentId,
        //  为必填 填写文件夹名即可
        fileName: fileName
      },
      header: {
        "Accept": "application/json" // 默认值
      },
      method: "post",
    }, res => {
      // console.log(res)
      if (res.msg == "SUCCESS"){
        this.tc('', 4)
        wx.showToast({
          title: '新建成功',
          icon: 'success',
          duration: 2000
        })

        
        this.getwenlist( this.data.thismuluid, this.data.wentime, this.data.wenpaixu)
      }


    })
  },


  // 四种操作
  sicaozuo: function (id, str,index=0) {
    var requestdata={}
    requestdata.id=id
    if(str=="changyong"){
      if(index==0){
        requestdata.isCommonly = 1
      }
      if (index == 1) {
        requestdata.isCommonly = 0
      }
      
    }
    if (str == "xingbiao") {

      if (index == 0) {
        requestdata.isFollow = 1
      }
      if (index == 1) {
        requestdata.isFollow = 0
      }
      
    }
    if (str == "chongmingming") {
      if (this.data.newFolderName==''){
        wx.showToast({
          title: '名称不能为空',
          icon: 'none',
          duration: 2000
        })
        return
      }

      if(this.data.currentcaozuo=='tu'){
        
        if (this.data.tulist[this.data.currentcaozuoindex].fileFormat == this.data.tulist[this.data.currentcaozuoindex].firstname){
          requestdata.fileName = this.data.newFolderName 
        }else{
          requestdata.fileName = this.data.newFolderName + '.' + this.data.tulist[this.data.currentcaozuoindex].fileFormat
        }
      }else{
       
        if (this.data.wenlist[this.data.currentcaozuoindex].fileFormat == this.data.wenlist[this.data.currentcaozuoindex].firstname){
          requestdata.fileName = this.data.newFolderName
        }else{
          requestdata.fileName = this.data.newFolderName + '.' + this.data.wenlist[this.data.currentcaozuoindex].fileFormat
        }
      }
    }
    if (str == "shanchu") {
      requestdata.isDelete = 1
    }

    ajax('/applet/appletRename', {
      data: requestdata,
        // id 为必填项
      // 1)设为常用 isCommonly为必填项 其他非必填 1为常用 0为非常用
      //     2)设为星标 isFollow为必填项 其他非必填 1为星标 0为非星标
      // 3) 重命名 fileName为必填项 其他非必填
      // 3) 删除 isDelete为必填项 其他非必填 1为删除 0为不删除
       
      
      header: {
        "Accept": "application/json" // 默认值
      },
      method: "post",
    }, res => {
      // console.log(res)
      if (res.msg == "SUCCESS") {

        if (str == "changyong") {
          this.tc("", 1)
        }
        if (str == "xingbiao") {
          this.tc("", 1)
        }
        if (str == "chongmingming") {
          this.tc("", 3)
        }
        if (str == "shanchu") {
          this.tc("", 2)
        }
        // this.tc('', 4)
        // wx.showToast({
        //   title: '新建成功',
        //   icon: 'success',
        //   duration: 2000
        // })

        this.gettulist( this.data.thismuluid, this.data.tutime, this.data.tupaixu)
        this.getwenlist( this.data.thismuluid, this.data.wentime, this.data.wenpaixu)
      }


    })
  },


  shewei:function(e){
    var str=e.currentTarget.dataset.str

    var index = e.currentTarget.dataset.index
    var id
    if(this.data.currentcaozuo=="tu"){
      id=this.data.tulist[this.data.currentcaozuoindex].id
    }else{
      id = this.data.wenlist[this.data.currentcaozuoindex].id
    }


    if (str == "changyong") {
      this.sicaozuo(id,'changyong',index)

    }
    if (str == "xingbiao") {
      this.sicaozuo(id, 'xingbiao',index)
    }
    if (str == "chongmingming") {
      this.tc("", 1)

      if (this.data.currentcaozuo == "tu") {

       

        this.setData({
          newFolderName: this.data.tulist[this.data.currentcaozuoindex].firstname
        })
      } else {

       

        this.setData({
          newFolderName: this.data.wenlist[this.data.currentcaozuoindex].firstname
        })
      }

      this.tc("",3)
      
    }
    if (str == "shanchu") {
      this.tc("", 1)
      this.tc("", 2)
    }
    if (str == "fenxiang") {
      var idlist=[]
      idlist.push(id)

   

      wx.navigateTo({
        url: '/pages/fenxiang/fenxiang?idlist=' + idlist,
      })
    }

  },

  sureupname:function(){
    var id
    if (this.data.currentcaozuo == "tu") {
      id = this.data.tulist[this.data.currentcaozuoindex].id
    } else {
      id = this.data.wenlist[this.data.currentcaozuoindex].id
    }
    this.sicaozuo(id, 'chongmingming')
  },

  suredel:function(){
    var id
    if (this.data.currentcaozuo == "tu") {
      id = this.data.tulist[this.data.currentcaozuoindex].id
    } else {
      id = this.data.wenlist[this.data.currentcaozuoindex].id
    }
    this.sicaozuo(id, 'shanchu')
  },


  setNewFolderName:function(e){
    // console.log(e.detail.value)
    this.setData({
      newFolderName: e.detail.value
    })
  },

  surecreateFolder:function(){
    
    this.createFolder( 0, this.data.newFolderName)
  },
 
  // 弹窗显示隐藏  
  // 1 showsantc 三个点 
  // 2 showdeltc 删除 
  // 3 showupnametc 重命名  
  // 4 shownewwjtc  新建文件夹
  // 5 showsxtc  筛选
  // 6 showjiahaotc 上传
  // 7 showyulantc  预览
  // 8 showjindutc 进度



  tc:function(e,aa=-1){
    var index
    if(aa!=-1){
      index=aa
    }else{
      index = e.currentTarget.dataset.index
    }
    
    if(index==1){
      this.setData({
        showsantc: !this.data.showsantc
      })
    } 
    if (index == 2) {
      this.setData({
        showdeltc: !this.data.showdeltc
      })
    }
    if (index == 3) {
      this.setData({
        showupnametc: !this.data.showupnametc
      })
    }
    if (index == 4) {
      this.setData({
        shownewwjtc: !this.data.shownewwjtc
      })
    }
    if (index == 5) {
      this.setData({
        showsxtc: !this.data.showsxtc
      })
    }
    if (index == 6) {
      this.setData({
        showjiahaotc: !this.data.showjiahaotc
      })
    }
    if (index == 7) {
      this.setData({
        showyulantc: !this.data.showyulantc
      })
    } if (index == 8) {
      this.setData({
        showjindutc: !this.data.showjindutc
      })
    }
  },


  tcc:function(e){
    
  },


  showsan:function(e){
    if (this.data.tushowallbox == true || this.data.wenshowallbox == true) {
      return
    }
    this.tc('', 1)
    var index = e.currentTarget.dataset.index

    var style = e.currentTarget.dataset.style
    this.setData({
      currentcaozuoindex:index,
      currentcaozuo:style
    })
  },

  settime(id){
    ajax('/applet/updateTime', {
      data: {
        id: id
      },
      header: {
        "Accept": "application/json" // 默认值
      },
      method: "post",
    }, res => {
      console.log(res.data.list)
      if (res.msg == "SUCCESS") {
        
      }
    })
  },

  totowenjian: function (e) {

    if (this.data.tushowallbox == true || this.data.wenshowallbox == true) {
      return
    }

    console.log(e)
    var id = e.currentTarget.dataset.id
    var type = e.currentTarget.dataset.type
    var muluname = e.currentTarget.dataset.muluname

    var src = e.currentTarget.dataset.src

    src = encodeURIComponent(src)

    console.log(src)

    var preview = e.currentTarget.dataset.preview
    var uuid = e.currentTarget.dataset.uuid

    
    if (type == 0) {
      wx.navigateTo({
        url: '/pages/towenjian/towenjian?thismuluid=' + id + '&muluname=' + muluname,
      })
    } else {
      if (preview==1){
        // wx.navigateTo({
        //   url: '/pages/details/details?src='+ src
        // })
        var huancun = wx.getStorageSync('huancun')

        if(huancun==''){
          huancun=[]
          wx.downloadFile({
            // 示例 url，并非真实存在
            url: decodeURIComponent(src),
            success: function (res) {
              console.log("aaa:" + "666a");
              const filePath = res.tempFilePath

    
              var item = {
                id: id,
                tempFilePath: filePath
              }
              huancun.push(item)

              wx.setStorageSync('huancun', huancun)

              wx.openDocument({
                filePath: filePath,
                success: function (res) {
                  console.log('打开文档成功')
                }
              })
            }
          })
        }else{

          var flage=-1
          for(var i=0;i<huancun.length;i++){
            if (huancun[i].id==id){
              flage=i
            }
          }

          if (flage!=-1){
            wx.openDocument({
              filePath: huancun[flage].tempFilePath,
              success: function (res) {
                console.log('打开文档成功')
              }
            })
          }else{
            wx.downloadFile({
              // 示例 url，并非真实存在
              url: decodeURIComponent(src),
              success: function (res) {
                console.log("aaa:" + "666a");
                const filePath = res.tempFilePath


                var item = {
                  id: id,
                  tempFilePath: filePath
                }
                huancun.push(item)

                wx.setStorageSync('huancun', huancun)

                wx.openDocument({
                  filePath: filePath,
                  success: function (res) {
                    console.log('打开文档成功')
                  }
                })
              }
            })
          }
        }

       

        this.settime(id)

      }else{
        this.setData({
          currentuuid: uuid
        })
        // wx.showToast({
        //   title: '该文件不可预览！',
        //   icon: 'none',
        //   duration: 2000
        // })

        this.setData({
          shownotyulantc: true
        })
      }
    }
  },

  copy: function (e) {

    var that = this;
    wx.setClipboardData({
      data: that.data.currentuuid,
      success: function (res) {
        that.ylquxiao()
      }
    });
  },

  addxinwenjianjia:function(){
    this.tc('', 6)
    this.tc('', 4)
  },
  


  // 选图片
  uploadimages: function () {
    this.tc('', 6)
    this.setData({
      headImg: []
    })
    
    var that = this
    wx.showActionSheet({
      itemList: ['从相册选取', '拍照'],
      success(res) {
        console.log(res.tapIndex)
        var index = res.tapIndex;

        var headImg = that.data.headImg;
        
        if (index == 0) {
          wx.chooseImage({
            count: 9,
            sizeType: ['original', 'compressed'],
            sourceType: ['album'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片
              const tempFilePaths = res.tempFilePaths;
              console.log(tempFilePaths)


              for (let i = 0; i < tempFilePaths.length; i++) {
                var obj = {}
                obj.path = tempFilePaths[i]
                headImg.push(obj)
              }
              that.setData({
                headImg: headImg
              });

              wx.navigateTo({ url: '/pages/shangchuan/shangchuan?headImg=' + JSON.stringify(headImg) + '&type=0' + '&thismuluid=' + that.data.thismuluid,})
            }
          })
        } else if (index == 1) {
          wx.chooseImage({
            count: 1,
            sizeType: ['original', 'compressed'],
            sourceType: ['camera'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片

              var headImg = that.data.headImg;

              const tempFilePaths = res.tempFilePaths;

              var obj = {}
              obj.path = tempFilePaths[0]
              headImg.push(obj)
              that.setData({
                headImg: headImg
              });
              wx.navigateTo({ url: '/pages/shangchuan/shangchuan?headImg=' + JSON.stringify(headImg) + '&type=0' + '&thismuluid=' + that.data.thismuluid, })
            }
          })
        }

      },
      fail(res) {
        console.log(res.errMsg)
      }
    })

  },
  // 选视频
  uploadvideo: function () {
    this.tc('', 6)
    this.setData({
      headImg:[]
    })
  
    var that = this
    wx.showActionSheet({
      itemList: ['从相册选取', '拍照'],
      success(res) {
        console.log(res.tapIndex)
        var index = res.tapIndex;

        var headImg = that.data.headImg;
        if (index == 0) {

          wx.chooseVideo({
            // count: num,
            maxDuration: 15,
            camera: 'back',

            sourceType: ['album'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片
              const tempFilePaths = res.tempFilePath;
              var obj = {}

              obj.path = tempFilePaths
              headImg.push(obj)
              that.setData({
                headImg: headImg
              });

              wx.navigateTo({ url: '/pages/shangchuan/shangchuan?headImg=' + JSON.stringify(headImg) + '&type=1' + '&thismuluid=' + that.data.thismuluid, })
            }
          })
        } else if (index == 1) {
          wx.chooseVideo({

            maxDuration: 15,
            camera: 'back',

            sourceType: ['camera'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片

              var headImg = that.data.headImg;

              const tempFilePaths = res.tempFilePath;

              var obj = {}
              obj.style = 2
              obj.path = tempFilePaths
              headImg.push(obj)

              that.setData({
                headImg: headImg
              });

              wx.navigateTo({ url: '/pages/shangchuan/shangchuan?headImg=' + JSON.stringify(headImg) + '&type=1' + '&thismuluid=' + that.data.thismuluid, })
            }
          })
        }

      },
      fail(res) {
        console.log(res.errMsg)
      }
    })

  },

  uploadwxwenjian:function(){

    this.tc('', 6)
    this.setData({
      headImg: []
    })

    var that = this
    wx.chooseMessageFile({
      count: 10,
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        var headImg = that.data.headImg;
        const tempFilePaths = res.tempFiles;
        console.log(tempFilePaths)


        for (let i = 0; i < tempFilePaths.length; i++) {
          var obj
          obj = tempFilePaths[i]
          headImg.push(obj)
        }
        that.setData({
          headImg: headImg
        });

        wx.navigateTo({ url: '/pages/shangchuan/shangchuan?headImg=' + JSON.stringify(headImg) + '&type=2' + '&thismuluid=' + that.data.thismuluid, })
      }
    })
  },
  



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  drew:function(){
    // 获得circle组件
    this.circle1 = this.selectComponent("#circle1");
    console.log(this.circle1)
    if (this.circle1==null){
      return
    }
    console.log(this.circle1)
    this.sleep(1000)
    // 绘制背景圆环
    this.circle1.drawCircleBg('circle_bg1', 78, 7)

    this.circle1.drawCircleBgg('circle_bgg1', 78, 13)
    // 绘制彩色圆环 

    // this.circle1.drawCircle('circle_draw1', 78, 7, 1);  

    // this.circle1.drawCircle('circle_draw1', 78, 7, 1);
    this.per1()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(wx.getStorageSync("isAudit")=='11111'){
      this.setData({
        isAudit:false
      })
    }else{
      this.setData({
        isAudit:true
      })
    }
    
    this.gettulist(this.data.thismuluid, this.data.tutime, this.data.tupaixu)
    this.getwenlist(this.data.thismuluid, this.data.wentime, this.data.wenpaixu)
  },

  // 预览框隐藏
  ylquxiao() {
    this.setData({
      shownotyulantc: false,
      currentuuid: ''
    })
  },

  plscquxiao() {
    this.setData({
      showpldeltc: false
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.setData({
      showsantc: false,
      showdeltc: false,
      showupnametc: false,
      shownewwjtc: false,
      showsxtc: false,
      showjiahaotc: false,

      showyulantc: false,
      showjindutc: false,

      //显示所欲box
      tushowallbox: false,
      wenshowallbox: false,

      //全选全局字段
      tuselectall: false,
      wenselectall: false,


      showpldeltc: false,
      shownotyulantc: false,

    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    this.gettulist(this.data.thismuluid, this.data.tutime, this.data.tupaixu)
    this.getwenlist(this.data.thismuluid, this.data.wentime, this.data.wenpaixu)
  }
})